package org.come.Jpanel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.Frame.ZhuFrame;
import org.come.bean.JadeorGoodstableBean;
import org.come.entity.Goodstable;
import org.come.mouslisten.RoleSuitMouslisten;
import org.come.mouslisten.StorageJadeMouslisten;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.Util;

import com.tool.btn.SwitchPageBtn;
import com.tool.btn.WorkshopBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;

 

/**
 * @author Administrator 套装升级
 */
public class UpgradeJpanel extends JPanel {

    private WorkshopBtn workshopBtn;// 升级按钮
    public static JLabel[] GoodsListLabel = new JLabel[21]; // 用来存放21个套装表格
    private static RoleSuitMouslisten[] suitMouslisten = new RoleSuitMouslisten[21]; // 21个套装表格监听
    private static JLabel labtz1,// 未升级的套装
            labtz2,// 已升级的套装
            labyf;// 玉符
    private static BigDecimal money;// 消耗金钱

    private SwitchPageBtn leftpageBtn,// 上一页按钮
            rightpageBtn;// 下一页按钮

    private static JadeorGoodstableBean goodstableBean = new JadeorGoodstableBean();
    private static Goodstable goodstable = new Goodstable();

    public static int page = 0;// 当前显示第几页装备

    public UpgradeJpanel() {
        if ("水墨UI".equals(MyIsif.getStyle())) {
            this.setPreferredSize(new Dimension(490, 428));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            // 未升级的套装
            labtz1 = new JLabel();
            labtz1.setBounds(239, 83, 54, 51);
            labtz1.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = goodstableBean.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labtz1);

            // 玉符
            labyf = new JLabel();
            labyf.setBounds(360, 83, 54, 51);
            labyf.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    int index = goodstableBean.getType() - 1;
                    if (goodstableBean.getPartJade() != null && index >= 0 && index < 5) {
                        StorageJadeMouslisten.showMsg(index);
                    }
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labyf);

            // 已升级的套装
            labtz2 = new JLabel();
            labtz2.setBounds(299, 183, 54, 51);
            labtz2.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = UpgradeJpanel.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labtz2);

            // 上一页按钮
            leftpageBtn = new SwitchPageBtn("skin/8100226/button/10.png", 1, 5);
            leftpageBtn.setBounds(120, 397, 18, 18);
            this.add(leftpageBtn);

            // 下一页按钮
            rightpageBtn = new SwitchPageBtn("skin/8100226/button/9.png", 1, 6);
            rightpageBtn.setBounds(145, 397, 18, 18);
            this.add(rightpageBtn);

            // 放置套装
            for (int i = 0; i < 21; i++) {
                GoodsListLabel[i] = new JLabel();
                int row = i % 3;
                int col = i / 3;
                GoodsListLabel[i].setBounds(15 + row * 51, 37 + col * 51, 49, 49);
                suitMouslisten[i] = new RoleSuitMouslisten(i, null, this);
                GoodsListLabel[i].addMouseListener(suitMouslisten[i]);
                this.add(GoodsListLabel[i]);
            }

            // 升级按钮
            workshopBtn = new WorkshopBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "升级", 4);
            workshopBtn.setBounds(288, 342, 59, 24);
            this.add(workshopBtn);
        } else {
            this.setPreferredSize(new Dimension(490, 428));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            // 未升级的套装
            labtz1 = new JLabel();
            labtz1.setBounds(239, 83, 54, 51);
            labtz1.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = goodstableBean.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labtz1);

            // 玉符
            labyf = new JLabel();
            labyf.setBounds(360, 83, 54, 51);
            labyf.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    int index = goodstableBean.getType() - 1;
                    if (goodstableBean.getPartJade() != null && index >= 0 && index < 5) {
                        StorageJadeMouslisten.showMsg(index);
                    }
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labyf);

            // 已升级的套装
            labtz2 = new JLabel();
            labtz2.setBounds(299, 183, 54, 51);
            labtz2.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = UpgradeJpanel.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labtz2);

            // 上一页按钮
            leftpageBtn = new SwitchPageBtn("inkImg/hongmu/2/30_png.button.btn_8.png", 1, 5);
            leftpageBtn.setBounds(120, 397, 18, 18);
            this.add(leftpageBtn);

            // 下一页按钮
            rightpageBtn = new SwitchPageBtn("inkImg/hongmu/2/36_png.button.btn_7.png", 1, 6);
            rightpageBtn.setBounds(145, 397, 18, 18);
            this.add(rightpageBtn);

            // 放置套装
            for (int i = 0; i < 21; i++) {
                GoodsListLabel[i] = new JLabel();
                int row = i % 3;
                int col = i / 3;
                GoodsListLabel[i].setBounds(15 + row * 51, 37 + col * 51, 49, 49);
                suitMouslisten[i] = new RoleSuitMouslisten(i, null, this);
                GoodsListLabel[i].addMouseListener(suitMouslisten[i]);
                this.add(GoodsListLabel[i]);
            }

            // 升级按钮
            workshopBtn = new WorkshopBtn("inkImg/hongmu/1/w50.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "升级", 4);
            workshopBtn.setBounds(288, 342, 60, 26);
            this.add(workshopBtn);
        }
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if ("水墨UI".equals(MyIsif.getStyle())) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B244.png");
            }
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 490, 428, this);
            // 画拥有金钱
            Util.drawMoney(g, 313, 312);
            // 画消耗金钱
            if (money != null) {
                Util.drawPrice(g, money, 313, 286);
            }
            // 画套装信息
            GoodsListFromServerUntil.drawRoleSuit(g, 15, 37, page, 21);
        } else {
            if (icon == null) {
                icon = new ImageIcon("inkImg/hongmu/2/setsynthesis_tzsj.png");
            }
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 490, 428, this);
            // 画拥有金钱
            Util.drawMoney(g, 313, 312);
            // 画消耗金钱
            if (money != null) {
                Util.drawPrice(g, money, 313, 286);
            }
            // 画套装信息
            GoodsListFromServerUntil.drawRoleSuit(g, 15, 37, page, 21);
        }
    }

    /**
     * 清空界面
     */
    public static void clearInterface() {
        money = null;
        goodstableBean.setGoodstable(null);
        goodstableBean.setPartJade(null);
        goodstableBean.setType(0);
        labtz1.setIcon(null);
        labyf.setIcon(null);
    }

    public static JLabel getLabtz1() {
        return labtz1;
    }

    public static void setLabtz1(JLabel labtz1) {
        UpgradeJpanel.labtz1 = labtz1;
    }

    public static JLabel getLabtz2() {
        return labtz2;
    }

    public static void setLabtz2(JLabel labtz2) {
        UpgradeJpanel.labtz2 = labtz2;
    }

    public static JLabel getLabyf() {
        return labyf;
    }

    public static void setLabyf(JLabel labyf) {
        UpgradeJpanel.labyf = labyf;
    }

    public static RoleSuitMouslisten[] getSuitMouslisten() {
        return suitMouslisten;
    }

    public static void setSuitMouslisten(RoleSuitMouslisten[] suitMouslisten) {
        UpgradeJpanel.suitMouslisten = suitMouslisten;
    }

    public static BigDecimal getMoney() {
        return money;
    }

    public static void setMoney(BigDecimal money) {
        UpgradeJpanel.money = money;
    }

    public static JadeorGoodstableBean getGoodstableBean() {
        return goodstableBean;
    }

    public static void setGoodstableBean(JadeorGoodstableBean goodstableBean) {
        UpgradeJpanel.goodstableBean = goodstableBean;
    }

    public static Goodstable getGoodstable() {
        return goodstable;
    }

    public static void setGoodstable(Goodstable goodstable) {
        UpgradeJpanel.goodstable = goodstable;
    }
}
